package sc;

import java.awt.Point;
import java.awt.Window;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JPanel;

public class BasePanel extends JPanel implements Comparable<BasePanel>, MouseListener, MouseMotionListener
{	
	private static final long serialVersionUID = 1L;
	private String sortvalue;
	private static int width;
	private static int drag_orig_x;
	private static int drag_orig_y;
	private static int drag_button;
	
	public BasePanel()
	{
		addMouseListener(this);
		addMouseMotionListener(this);
	}
	
	public int compareTo(BasePanel o)
	{
		return this.sortvalue.compareToIgnoreCase(o.sortvalue);
	}
	
	public void sortValue(String sortvalue)
	{
		this.sortvalue = sortvalue;
	}
	
	public String sortValue()
	{
		return this.sortvalue;
	}
	
	public static void width(int width)
	{
		BasePanel.width = width;
	}

	public static int width()
	{
		return BasePanel.width;
	}

	public void mouseClicked(MouseEvent e)
	{
	}

	public void mouseEntered(MouseEvent e)
	{
		// Mouse is no longer over a popup, so tell them all to hide
		TopPanel.hidePopupMenu();
		Member.hidePopupMenu();
	}

	public void mouseExited(MouseEvent e)
	{
	}

	public void mousePressed(MouseEvent e)
	{
		int x = e.getX();
		int y = e.getY();
		drag_orig_x = x;
		drag_orig_y = y;
		Harlequin.getInstance().setAlwaysOnTop(true);
		Harlequin.getInstance().setAlwaysOnTop(false);
		drag_button = e.getButton();
	}

	public void mouseReleased(MouseEvent e)
	{
	}

	public void mouseDragged(MouseEvent e)
	{
		int x = e.getX();
		int y = e.getY();
		
		if (drag_button == MouseEvent.BUTTON3 || (Math.abs(drag_orig_x - x) < 3 && Math.abs(drag_orig_y - y) < 3))
			return;
		
		Window w = Harlequin.getInstance();
		Point p = w.getLocation();
		w.setLocation((x - drag_orig_x) + p.x, (y - drag_orig_y) + p.y);
	}

	public void mouseMoved(MouseEvent e)
	{
	}
}
